package com.hxd.otc.module.order.adapter;

import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.hxd.otc.R;
import com.hxd.otc.module.order.bean.BankInfoPoData;
import com.hxd.otc.utils.LogUtils;
import com.hxd.otc.utils.UIUtils;

/**
 * 包  名 :  com.hxd.otc.module.order.adapter
 * 类  名 :  OrderDetailBankAdapter
 * 作  者 :  zjl
 * 时  间 :  2018/6/15 17:42
 * 描  述 :  ${TODO}订单详情页---银行卡信息
 */
public class OrderDetailBankAdapter extends BaseQuickAdapter<BankInfoPoData, BaseViewHolder> {

    boolean isQrCodeGone;

    public OrderDetailBankAdapter() {
        super(R.layout.adapter_order_detail_bank, null);
    }

    public void isQrcodeGone(boolean isGone) {
        isQrCodeGone = isGone;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, @NonNull final BankInfoPoData item) {
        helper.setText(R.id.tv_bank_name, item.bankName);
        helper.setText(R.id.tv_name, item.realName);
        helper.setGone(R.id.tv_remark, !TextUtils.isEmpty(item.remarks));
        helper.setText(R.id.tv_remark, item.remarks);
        helper.setText(R.id.tv_bank_number, item.payNo);
        switch (item.type) {
            //类型，1微信2支付宝3银行卡
            case 1:
                ((TextView) helper.getView(R.id.tv_bank_number)).setCompoundDrawablesWithIntrinsicBounds(
                        null, null, null, null);
                ((TextView) helper.getView(R.id.tv_name)).setCompoundDrawablesWithIntrinsicBounds(
                        null, null, null, null);
                helper.setGone(R.id.iv_alipay, !isQrCodeGone);
                helper.setImageResource(R.id.iv_bank, R.mipmap.order_card_wechat);
                break;
            case 2:
                ((TextView) helper.getView(R.id.tv_bank_number)).setCompoundDrawablesWithIntrinsicBounds(
                        null, null, null, null);
                ((TextView) helper.getView(R.id.tv_name)).setCompoundDrawablesWithIntrinsicBounds(
                        null, null, null, null);
                helper.setGone(R.id.iv_alipay, !isQrCodeGone);
                helper.setImageResource(R.id.iv_bank, R.mipmap.order_treasure_icon);
                break;
            case 3:
                ((TextView) helper.getView(R.id.tv_bank_number)).setCompoundDrawablesWithIntrinsicBounds(
                        null, null, ContextCompat.getDrawable(UIUtils.getContext(), R.mipmap.me_copy), null);
                ((TextView) helper.getView(R.id.tv_name)).setCompoundDrawablesWithIntrinsicBounds(
                        null, null, ContextCompat.getDrawable(UIUtils.getContext(), R.mipmap.me_copy), null);
                helper.setGone(R.id.iv_alipay, false);
                helper.setGone(R.id.iv_bank, !isQrCodeGone);
                helper.setImageResource(R.id.iv_bank, R.mipmap.order_card_icon);
                break;
        }

        helper.getView(R.id.tv_bank_number).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (linenster != null)
                    linenster.clickNumber(item);
            }
        });

        helper.getView(R.id.tv_name).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (linenster != null)
                    linenster.clickName(item);
            }
        });
        helper.getView(R.id.rl_item).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (linenster != null)
                    linenster.clickItem(item);
            }
        });

    }

    OnItemClickLinenster linenster;

    public void setLinenster(OnItemClickLinenster linenster) {
        this.linenster = linenster;
    }

    public interface OnItemClickLinenster {
        void clickName(BankInfoPoData item);

        void clickNumber(BankInfoPoData item);

        void clickItem(BankInfoPoData item);
    }
}
